// import 'package:flutter/material.dart';
/*
* 配置iOS风格的路由 (安卓:向上弹出,iOS:左滑右滑)
* 1.删除material.dart引入cupertino.dart
* 2.把MaterialPageRoute 替换成 CupertinoPageRoute
* */
import 'package:flutter/cupertino.dart';

import '../pages/bars.dart';
import '../pages/shop.dart';
import '../pages/user/login.dart';
import '../pages/user/registerFirst.dart';
import '../pages/user/registerSecond.dart';
import '../pages/user/registerThird.dart';

// 1.配置路由
final Map routes = {
  "/": (context) => const Bars(),
  "/login": (context, {arguments}) => LoginPage(),
  "/registerFirst": (context, {arguments}) => RegisterFirstPage(),
  "/registerSecond": (context, {arguments}) => RegisterSecondPage(),
  "/registerThird": (context, {arguments}) => RegisterThirdPage(),
  "/shop": (context, {arguments}) => ShopPage(arguments: arguments)
};

// 2.配置onGenerateRoute 固定写法 这个方法相当于中间件 这里面可以做权限判断
var onGenerateRoute = (RouteSettings settings) {
  // print(settings);
  // print(settings.name);
  // print(settings.arguments);
  // 统一处理
  final String? name = settings.name; // /news 或者 /search
  final Function? pageContentBuilder =
      routes[name]; // Function (context) => const NewsPage()
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = CupertinoPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
          CupertinoPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
  return null;
};
